import { defineStore } from 'pinia'
interface AuthInterface {
    userName?: string
    isSuperAdmin: 1|0
    permissions?: string[]
}
const defaultAuth:AuthInterface = {
    userName: '',
    isSuperAdmin: 0,
    permissions: []
}

export const useAuthStore = defineStore('auth', {
    state : () =>  ({...defaultAuth}),
    actions: {
        init() {
            this.$state = JSON.parse(localStorage.getItem("user-auth") || '{}') || defaultAuth;
        },
        logout() {
            this.$reset();
            localStorage.removeItem("user-auth");
        }
    },
})